$("#gridDanhSachNhanVien").jqGrid({        
   	url:'/baocaodoanhthu/json/?func=getListDoanhThu',
	datatype: "json",
   	colNames:['Nhân viên','Khách hàng', 'Doanh thu', 'Công nợ','Tổng thu'],
   	colModel:[
   		{name:'tenNV',index:'tenNV', width:90, editable:true},
   		{name:'tenKH',index:'tenKH', width:90, editable:true},
   		{name:'doanhThu',index:'doanhThu', width:90, editable:true, formatter:"number", summaryType:'sum'},
   		{name:'congNo',index:'congNo', width:90, editable:true, formatter:"number", summaryType:'sum'},
   		{name:'tongThu',index:'tongThu', width:90, editable:true, formatter:"number", summaryType:'sum'}
   	],
   	rowNum:10,
   	gridview: true,
   	rowList:[10,20,30],
   	pager: '#pDanhSachNhanVien',
   	sortname: 'tenNV',
    viewrecords: true,
    loadonce: false,
    sortorder: "desc",
	jsonReader: {
		repeatitems : false,
		id: "0"
	},
	grouping:true,
   	groupingView : {
   		groupField : ['tenNV'],
   		groupSummary : [true],
   		groupColumnShow : [true],
   		groupText : ['<b>{0}</b>'],
   		groupCollapse : false,
		groupOrder: ['asc']
   	},
	caption: "Báo cáo doanh thu",
	width: '971',
    height: '100%'
});
jQuery("#gridDanhSachNhanVien").jqGrid('navGrid','#pDanhSachNhanVien',
									{
										edit:false,
										add:false,
										del:false
									});

$('#search').click(function() {
	$("#gridDanhSachNhanVien")
		.jqGrid()
		.setGridParam({url : '/baocaodoanhthu/json/?func=getListDoanhThu'
			+ '&maNhanVien=' + $('#cbbNhanVien').val()
			+ '&maKhachHang=' + $('#cbbKhachHang').val()
			+'&tuNgay=' + $('#tuNgay').val()
			+'&denNgay=' + $('#denNgay').val()
			})
			.trigger('reloadGrid');
});

$('#cbbNhanVien').change(function() {
	//lay danh sach khach hang ve dua vao combobox
	$.get('/quanlygiaban/json/?func=getListKhachHang&maNV=' + $('#cbbNhanVien').val(), function(data){
		var lstKhachHang = '';
		var select = $('#cbbKhachHang');
		select.find('option').remove();
		var obj = JSON.parse(data);
		var all = document.createElement("option");
		all.value = '';
		all.innerHTML = "Tất cả";
		select.append(all);
		for (var i=0; i < obj.length; i++)
		{
		  var option = document.createElement("option");
		  option.value = obj[i].id;
		  option.innerHTML = obj[i].tenKhachHang;
		  select.append(option);
		  
		  obj[i].tenKhachHang = obj[i].id + ' - ' + obj[i].tenKhachHang
          lstKhachHang += obj[i].id + ':' + obj[i].tenKhachHang + ';'
		}
		$('#lstKhachHang').val(lstKhachHang);
	});
});
$(document).ready(function() {
	
	$('#KeToan').addClass('Active');
	$('#tuNgay').datepicker({ dateFormat: "dd/mm/yy" });
	$('#denNgay').datepicker({ dateFormat: "dd/mm/yy" });
});